*---------------------------------------------TAX_CAP_EST_IVREG2.DO-----------------------------------------
*This script assesses the extent of capitalization of temporarily low property tax liabilities due to
*capping of taxable values until Jan. 1 following sales using data obtained from the City Assessor.  

*Sebastien Bradley 6/10/10

*Modified 12/11/13 to examine reduced form effect of yearsheld on sale prices, including for properties with 0 capped TV benefit.

clear all
local path "C:/Users/sjb355/Documents/Research/PropertyTaxes/Ann_Arbor/AA_proptaxdata19972008"
capture cd `path'
set matsize 600
capture log close
set more off

log using tax_cap_est_results_ivreg2.txt, text replace

/**/
*CLEAN-UP DATA
use AA_GIS_data.dta
drop propaddresscombined
drop if class~=401			/*Focus on residential property only*/
drop if tv==.

*Perform data clean-up for sales involving non-market transaction prices (based on consultation of http://www.a2gov.org/departments/finance-admin-services/assessing/Pages/OnLineDisclamier.aspx).
*Mis-recorded prices:
replace saleamt = 280000 if pid=="09-09-30-111-023" & saleamt==28000
replace saleamt = 525000 if pid=="09-09-34-109-005" & saleamt==52500
replace saleamt = 596000 if pid=="09-09-34-102-002" & saleamt==59600
replace saleamt = saleamt+199000 if pid=="09-09-21-213-019" & saleamt==7040
replace saleamt = saleamt+114900 if pid=="09-12-04-116-025" & saleamt==65000

*Related party transactions:
drop if saleamt<=100
gen dp = saleamt-l_saleamt
gen dpp = dp/l_saleamt
gen psevratio = saleamt/(2*sev)
gen f_psevratio = saleamt/(2*f_sev)

drop if f_psevratio>float(1.86) & f_psevratio~=.				/*Absurdly high prices = top 1 percent of overpayments relative to POST-SALE SEV*/
drop if psevratio<float(0.5) & (float(dpp)<=-0.180 | dpp==.) 	/*Artificially low prices*/
drop if psevratio<float(0.5) & f_sev>f_tv & f_sev~=. & f_tv~=. 	/*Artificially low prices and no TV uncapping*/
drop if pid=="09-09-10-400-273" & saleamt==5610		/*Observed related party (e.g. divorce)*/
drop if pid=="09-09-29-324-009" & saleamt==5818		/*Observed related party (e.g. divorce)*/
drop if pid=="09-09-27-100-024" & saleamt==20000	/*Observed related party (e.g. divorce)*/
drop if pid=="09-09-29-220-001" & saleamt==33378	/*Observed related party (e.g. divorce)*/
drop if pid=="09-09-19-320-008" & saleamt==33500	/*Observed related party (e.g. divorce)*/
drop if pid=="09-09-20-311-006" & saleamt==90000	/*Observed related party (e.g. divorce)*/
drop if pid=="09-09-31-118-009" & saleamt==45000	/*Observed related party (e.g. divorce)*/
*Remaining <5 percent of sales with greatest price declines (i.e. dpp<-0.180 but ratio of sale price to assessed market 
*value>50 percent) should be generally legitimate arm's-length transactions (including parcel splits).

*Drop all high-frequency sale observations (i.e. multiple parcel sales within the same year)
*Maximum number of sales within year = 4 in data
sort pid saledate saleamt
gen I_multisale = ((pid==pid[_n-1] & saleyear==saleyear[_n-1]) | (pid==pid[_n+1] & saleyear==saleyear[_n+1]))
drop if I_multisale==1

sort pid saledate


*Add AA tax rate information.  (Since PRE status is unknown, assume all homes face preferential homestead rate).
local y = "1997"
gen mills = 49.7825 if saleyear==`y'
gen f_mills = .
foreach m in 49.3022 48.3181 47.4614 46.802 47.5568 45.4418 47.3625 46.7755 46.1895 46.0373 45.6098 45.1876 {
	replace f_mills = `m' if saleyear==`y'
	local y = `y'+1
	replace mills = `m' if saleyear==`y'
}
replace mills = mills/1000
replace f_mills = f_mills/1000

*ADDED 5/5/15:
*Alternately, assume non-homestead rates:  /*In logs, year invariant millage rates are absorbed in year FE, so no expected effect on point estimates*/
local y = "1997"
gen mills_nonpre = 58.8097 if saleyear==`y'
gen f_mills_nonpre = .
foreach m in 58.8566 58.0204 58.1021 57.7565 58.9490 57.7879 59.6817 59.2397 59.1823 59.2835 59.2935 58.7369 {
	replace f_mills_nonpre = `m' if saleyear==`y'
	local y = `y'+1
	replace mills_nonpre = `m' if saleyear==`y'
}


*CONSTRUCT REGRESSION VARIABLES:
*Tax benefits from inheritted capped TV are proportional to the number of days remaining until uncapping:
gen saledayofyear = doy(saledate)
gen tenancydays = 365-saledayofyear
replace tenancydays = 366-saledayofyear if saleyear==2004 | saleyear==2008
gen d = tenancydays/365		/*Fraction of year remaining*/
replace d = tenancydays/366 if saleyear==2000 | saleyear==2004 | saleyear==2008

*Covariates:
*Construct sale year, quarter, and month dummies to account for seasonal demand patterns and year FE
qui tab saleyear, gen(saleyear_dum)
gen salequarter = quarter(saledate)
qui tab salequarter, gen(quarter_dum)
qui tab salemonth, gen(month_dum)

*Categorize 50 neighborhoods used by A2 Assessor.
tab neighborhood, gen(hood)

*Categorize elementary, middle, and high schools:
foreach level in elem mid high {
	tab `level'_sch, gen(`level'_sch)
}

replace resyearbuilt = . if resyearbuilt>saleyear
gen actualage = saleyear-resyearbuilt
gen actualage2 = actualage^2

save tax_cap_est_data.dta, replace
/**/


use tax_cap_est_data.dta

drop if saleyear==2008											/*Too few 2008 observations to warrant estimating year FE*/
gen I_new = (resyearbuilt==saleyear | resyearbuilt==saleyear-1)	/*Flag new construction*/

replace resfloorarea = resfloorarea/1000
replace resgaragearea = resgaragearea/1000


*------------------------------------------------------------------------------------------------------------------------------------------------------
*Compute tax benefit associated with inheriting capped TV for the year in which sale occurs
local av = "sev"
local indep = "tvcapval"

local tau = "mills"
*local tau = "mills_nonpre"

local se = "vce(cluster neighborhood)"

gen tvcapval = (`av'-tv)*`tau'*d	/*Pro-rated*/
gen d_tax = (`av'-tv)*`tau'			/*Full-year capped TV tax benefit*/
*------------------------------------------------------------------------------------------------------------------------------------------------------

drop if tvcapval<0								/*One screwy observation*/

*Impose censoring to distribution of sale prices
summ saleamt, detail
drop if saleamt>500000			/*Used for initial REStat submission*/
local subf = "/500kCens"

*drop if saleamt>250000			/*Tested 4/14/15 at referee request*/
*local subf = "/250kCens"
*local subf = "/Uncens"

local outpath "`path'/TEX_Tables/HoodYearFE`subf'"
capture mkdir "`outpath'"

local area_X = "hood1-hood47"												/*Omits Neighborhood 52*/
local school_X = "elem_sch1-elem_sch17 mid_sch1 mid_sch2 mid_sch4 mid_sch5 high_sch1 high_sch2"		/*Omits Wines, Scarlett, and Skyline*/
local year_X = "saleyear_dum1-saleyear_dum10"								/*Omits 2007*/
local quarter_X = "quarter_dum1-quarter_dum3"
local month_X = "month_dum1-month_dum11"

local house_X = "E_saleamt_enc resfloorarea resgaragearea resnumbed resfullbaths reshalfbaths actualage actualage2 renovage"

*Define neighborhood-year FE:
quietly {
 foreach h of varlist `area_X' {
	foreach y of varlist `year_X' {
		local yy = "year_"+substr("`y'",13,length("`y'")-13+1)
		gen `h'_x_`yy' = `h'*`y'
	}
 }
}
local area_x_year = "hood*_x_year*"
local area_X = "`area_X' `area_x_year'"

*Define yearsheld-year instruments:
forvalues yy = 1/11 {
	gen yearsheld_x_yr`yy' = yearsheld*saleyear_dum`yy'
}
local yearsheld_x_yr = "yearsheld yearsheld_x_yr4-yearsheld_x_yr11"



*ESTIMATE
*INCLUDE RHS MEASURE OF "PREDICTED" SALE PRICE USING LAST SALE PRICE INFLATED BY HPI GROWTH
gen E_saleamt_enc = l_saleamt*(enc_hpi/l_enc_hpi)	/*East North Central Census Division*/

*CONSTRUCT CANDIDATE INSTRUMENTS:
sort pid saledate saleamt
by pid: gen sev_hist = sev[_n-1]
gen E_sev_ai = sev_hist*(ai/l_ai)*`tau'			/*Ann Arbor average assessed value growth*/
gen E_sev_irmi = sev_hist*(irmi/l_irmi)*`tau'
gen E_d_tax = E_sev_ai - E_sev_irmi

disp "REGRESSIONS BY `indep'"
disp "Assessed value = `av'"


*Report correlations among covariates
pwcorr `house_X' yearsheld `indep' E_d_tax tv E_sev_irmi f_sev sev E_sev_ai


*ESTIMATE MAIN SPECIFICATIONS:
local ivcmd = "ivreg2"
local ivopt = "cluster(neighborhood) first partial(`area_X' `school_X' `year_X' `month_X')"


*PERFORM IN LOGS
foreach v in saleamt tvcapval d_tax d E_saleamt_enc E_d_tax {
	gen log_`v' = log(`v')
}
gen renovamt_sh = renovamt/l_saleamt
local log_house_X = "log_E_saleamt_enc resfloorarea resgaragearea resnumbed resfullbaths reshalfbaths actualage actualage2 renovage"

/**/
*USED TO PRODUCE SPECIFICATION (1) RESULTS SHOWN IN TABLES 2, 3, AND A2-3 :
#delimit ;
reg log_saleamt log_`indep' `log_house_X' `area_X' `school_X' `year_X' `class_X' `month_X' if yearsheld~=., `se';
estimates store ols_spec1;

`ivcmd' log_saleamt `log_house_X' `area_X' `school_X' `year_X' `class_X' `month_X' (log_`indep' = yearsheld), `ivopt'
	endog(log_`indep') savefirst savefprefix("iv1_s1_") rf;
estimates store iv1_stage2;
summarize tvcapval if e(sample), detail;
summarize d_tax if e(sample), detail;
summarize saleamt if e(sample), detail;

`ivcmd' log_saleamt `log_house_X' `area_X' `school_X' `year_X' `class_X' `month_X' (log_`indep' = log_E_d_tax), `ivopt'
	endog(log_`indep') savefirst savefprefix("iv1_s1_alt_") rf;
estimates store iv1_stage2_alt;
summarize tvcapval if e(sample), detail;
summarize d_tax if e(sample), detail;
summarize saleamt if e(sample), detail;

`ivcmd' log_saleamt `log_house_X' `area_X' `school_X' `year_X' `class_X' `month_X' (log_`indep' = `yearsheld_x_yr'), `ivopt'
	endog(log_`indep') savefirst savefprefix("iv1_s1_alt2_") rf redundant(yearsheld_x_yr4-yearsheld_x_yr11);
estimates store iv1_stage2_alt2;

#delimit cr
/**/

*ADD RHS CONTROL FOR FUTURE TAX LIABILITY (AS IN CAPITALIZATION MODEL)
*Compute period 0 full-year tax liability
gen tax_0 = tv*`tau'
*Compute period n>0 full-year tax liability
gen tax_n = f_sev*`tau'
gen prox_tax_n = `av'*`tau'

foreach v in tax_0 tax_n prox_tax_n E_sev_ai {
	gen log_`v' = log(`v')
}

/**/
*USED TO PRODUCE SPECIFICATION (2) RESULTS SHOWN IN TABLES 2, 3, AND A2-3 :
#delimit ;
reg log_saleamt log_`indep' log_prox_tax_n `log_house_X' `area_X' `school_X' `year_X' `month_X' if yearsheld~=. & E_sev_ai~=., `se';
estimates store ols_spec2;

`ivcmd' log_saleamt `log_house_X' `area_X' `school_X' `year_X' `month_X' (log_`indep' log_prox_tax_n = yearsheld log_E_sev_ai), `ivopt'
	/*endog(log_`indep' log_prox_tax_n)*/ savefirst savefprefix("iv2_s1_") rf;
estimates store iv2_stage2;
summarize tvcapval if e(sample), detail;
summarize d_tax if e(sample), detail;
summarize saleamt if e(sample), detail;

`ivcmd' log_saleamt `log_house_X' `area_X' `school_X' `year_X' `month_X' (log_`indep' log_prox_tax_n = log_E_d_tax log_E_sev_ai), `ivopt'
	/*endog(log_`indep' log_prox_tax_n)*/ savefirst savefprefix("iv2_s1_alt_") rf;
estimates store iv2_stage2_alt;

`ivcmd' log_saleamt `log_house_X' `area_X' `school_X' `year_X' `month_X' (log_`indep' log_prox_tax_n = `yearsheld_x_yr' log_E_sev_ai), `ivopt'
	/*endog(log_`indep' log_prox_tax_n)*/ savefirst savefprefix("iv2_s1_alt2_") rf redundant(yearsheld_x_yr4-yearsheld_x_yr11);
estimates store iv2_stage2_alt2;


/**/
*USED TO PRODUCE RESULTS SHOWN IN TABLE A1 ;
*Add reduced form regression (including separate regression for properties with TV = SEV prior to sale);
reg log_saleamt yearsheld log_E_sev_ai `log_house_X' `area_X' `school_X' `year_X' `class_X' `month_X' if log_`indep'~=., `se';
estimates store rf1;
tab yearsheld saleyear if e(sample);
summarize yearsheld if e(sample), detail;
reg log_saleamt yearsheld log_E_sev_ai `log_house_X' `area_X' `school_X' `year_X' `class_X' `month_X' if `indep'==0, `se';
estimates store rf2;
tab yearsheld saleyear if e(sample);
summarize yearsheld if e(sample), detail;

*Force joint estimation with capped TV benefit = 0 sample;
gen I_`indep'0 = (`indep'==0) if `indep'~=.;
reg log_saleamt c.yearsheld##i.I_`indep'0 log_E_sev_ai `log_house_X' `area_X' `school_X' `year_X' `class_X' `month_X', `se';
estimates store rf3;
/**/

*Output Key Results;
outreg2 log_`indep' log_prox_tax_n `log_house_X' [ols_spec1 ols_spec2] using "`outpath'/ols_`indep'", replace tex stats(coef se) paren(se) symbol(***,**,*) 
	/*side*/ dec(3) adjr2 nocons title("OLS Capitalization Results");
outreg2 log_`indep' log_prox_tax_n `log_house_X' [iv1_stage2 iv2_stage2 iv1_stage2_alt iv2_stage2_alt iv1_stage2_alt2 iv2_stage2_alt2] using "`outpath'/iv_stage2_`indep'", replace tex stats(coef se) paren(se) 
	symbol(***,**,*) /*side*/ dec(3) adjr2 nocons title("IV Capitalization Results");
outreg2 [rf1 rf2 rf3] using "`outpath'/rf_`indep'", replace tex stats(coef se) paren(se) symbol(***,**,*) /*side*/ dec(3) adjr2 nocons title("Reduced Form Results");

#delimit cr
/**/

/*
*TEST FOR BUBBLE EFFECT:
*REPEAT WITH INTERACTION FOR PRE/POST-BUBBLE DUMMY
gen I_pastpeak = (saleyear>=2006)
*gen I_pastpeak = (saleyear>=2007)
foreach v in log_`indep' log_prox_tax_n yearsheld log_E_sev_ai {
	gen `v'_x_pastpeak = `v'*I_pastpeak
}

#delimit ;
local ivopt = "cluster(neighborhood) first partial(hood1-hood47 `month_X')";
reg log_saleamt log_`indep' log_prox_tax_n `log_house_X' hood1-hood47 `school_X' `year_X' `month_X' if !I_pastpeak & yearsheld~=. & E_sev_ai~=., `se';
reg log_saleamt log_`indep' log_prox_tax_n `log_house_X' hood1-hood47 `school_X' `year_X' `month_X' if I_pastpeak & yearsheld~=. & E_sev_ai~=., `se';

`ivcmd' log_saleamt `log_house_X' hood1-hood47 `school_X' `year_X' `month_X' (log_`indep' log_prox_tax_n = yearsheld log_E_sev_ai) if !I_pastpeak, `ivopt';
`ivcmd' log_saleamt `log_house_X' hood1-hood47 `school_X' `year_X' `month_X' (log_`indep' log_prox_tax_n = yearsheld log_E_sev_ai) if I_pastpeak, `ivopt';

reg log_saleamt log_`indep' log_prox_tax_n i.I_pastpeak c.log_`indep'#i.I_pastpeak c.log_prox_tax_n#i.I_pastpeak `log_house_X' `area_X' `school_X' `year_X' `month_X' if yearsheld~=. & E_sev_ai~=., `se';
summarize tvcapval d_tax if e(sample), detail; 
`ivcmd' log_saleamt I_pastpeak `log_house_X' hood1-hood47 `school_X' `year_X' `month_X' 
	(log_`indep' log_prox_tax_n log_`indep'_x_pastpeak log_prox_tax_n_x_pastpeak = yearsheld log_E_sev_ai yearsheld_x_pastpeak log_E_sev_ai_x_pastpeak), `ivopt';
summarize tvcapval d_tax if e(sample), detail; 
	
#delimit cr
*/


/**/
*TEST WHETHER CAPITALIZATION OF TV UNCAPPING BENEFITS DIFFERS IN DECEMBER OR JANUARY VS. OTHER TIMES OF YEAR:
*Confounding factor:  for December purchases, TV uncapping ought to have been especially salient, but buyers for whom this was most salient
*may have chosen to delay buying until January, leaving only the unsophisticated behind.  Conversely, January buyers might not be alert to 
*TV uncapping one year later, or they may have delayed buying from December precisely to avoid TV uncapping.
*Solution (4/22/15):  Iteratively test over a widening donut
*USED TO PRODUCE RESULTS SHOWN IN TABLE 4 :

gen cutoffyear = saleyear
replace cutoffyear = saleyear+1 if salemonth>=7 & salemonth<=12
qui tab cutoffyear, gen(cutoffyear_dum)
local cyear_X = "cutoffyear_dum1-cutoffyear_dum10"

#delimit ;
local ivopt = "cluster(neighborhood) first partial(`area_X' `school_X' `cyear_X' month_dum*)";
forvalues m = 1/6 {;
	gen I_`m'm = (salemonth>=1 & salemonth<=`m') if (salemonth>=1 & salemonth<=`m') | (salemonth>=`=12-`m'+1' & salemonth<=12);
	gen log_d_tax_x_`m'm = log_d_tax*I_`m'm;
	gen yearsheld_x_`m'm = yearsheld*I_`m'm;
	
	reg log_saleamt c.log_d_tax##i.I_`m'm log_prox_tax_n `log_house_X' `area_X' `school_X' `cyear_X' month_dum* if yearsheld~=. & E_sev_ai~=., `se';
	estimates store ols_`m'm;
	`ivcmd' log_saleamt `log_house_X' `area_X' `school_X' `cyear_X' month_dum* (log_d_tax log_d_tax_x_`m'm log_prox_tax_n = yearsheld yearsheld_x_`m'm log_E_sev_ai), `ivopt';
	estimates store iv_`m'm;
	summ tvcapval d_tax if e(sample) & I_`m'm==0;
	summ tvcapval d_tax if e(sample) & I_`m'm==1;
	
	if `m'>1 {;
		gen I_donut_`m'm = (salemonth>=2 & salemonth<=`m') if (salemonth>=2 & salemonth<=`m') | (salemonth>=`=12-`m'+1' & salemonth<=11);
		gen log_d_tax_x_donut_`m'm = log_d_tax*I_donut_`m'm;
		gen yearsheld_x_donut_`m'm = yearsheld*I_donut_`m'm;

		reg log_saleamt c.log_d_tax##i.I_donut_`m'm log_prox_tax_n `log_house_X' `area_X' `school_X' `cyear_X' month_dum* if yearsheld~=. & E_sev_ai~=., `se';
		estimates store ols_donut_`m'm;
		`ivcmd' log_saleamt `log_house_X' `area_X' `school_X' `cyear_X' month_dum* (log_d_tax log_d_tax_x_donut_`m'm log_prox_tax_n = yearsheld yearsheld_x_donut_`m'm log_E_sev_ai), `ivopt';		
		estimates store iv_donut_`m'm;
		summ tvcapval d_tax if e(sample) & I_donut_`m'm==0;
		summ tvcapval d_tax if e(sample) & I_donut_`m'm==1;
	};

	*Output Key Results;
	if `m'==1 {;
		local outopt = "replace";
	};
	else if `m'==2 {;
		local outopt = "";
		local outopt_donut = "replace";
	};
	else {;
		local outopt_donut = "";
	};
	outreg2 [ols_`m'm] using "`outpath'/ols_d_tax", keep(log_d_tax log_prox_tax_n 1.I_`m'm#c.log_d_tax 1.I_`m'm `log_house_X') `outopt' tex stats(coef se) paren(se) symbol(***,**,*) 
		/*side*/ dec(3) adjr2 nocons title("OLS Capitalization Results") ctitle("+/- `m' Months");
	outreg2 [iv_`m'm] using "`outpath'/iv_stage2_d_tax", keep(log_d_tax log_prox_tax_n log_d_tax_x_`m'm `log_house_X')`outopt' tex stats(coef se) paren(se) 
		symbol(***,**,*) /*side*/ dec(3) adjr2 nocons title("IV Capitalization Results") ctitle("+/- `m' Months");
	
	if `m'>=2 {;
	  outreg2 [ols_donut_`m'm] using "`outpath'/ols_donut_d_tax", keep(log_d_tax log_prox_tax_n 1.I_donut_`m'm#c.log_d_tax 1.I_donut_`m'm `log_house_X') `outopt_donut' tex stats(coef se) paren(se) symbol(***,**,*) 
		/*side*/ dec(3) adjr2 nocons title("OLS Capitalization Results") ctitle("+/- `m' Months");
	  outreg2 [iv_donut_`m'm] using "`outpath'/iv_donut_stage2_d_tax", keep(log_d_tax log_prox_tax_n log_d_tax_x_donut_`m'm `log_house_X')`outopt_donut' tex stats(coef se) paren(se) 
		symbol(***,**,*) /*side*/ dec(3) adjr2 nocons title("IV Capitalization Results") ctitle("+/- `m' Months");
	};
};

local ivopt = "cluster(neighborhood) first partial(`area_X' `school_X' `year_X' `month_X')";	
#delimit cr
/**/


*RE-ESTIMATE SEPARATELY ACCORDING TO WHETHER SALES FALL WITHIN CENSUS TRACTS CHARACTERIZED BY ABOVE-MEDIAN EDUCATION AND FAMILIARITY WITH MICHIGAN, ETC.
*USED TO PRODUCE RESULTS SHOWN IN TABLE 5:
*Perform modified calculation to identify median characteristics among realized sales only.  Otherwise, position of median is affected by tracts with no sales.
foreach v in educ_lt12_pct educ_colldeg_pct res_nonmi_pct res_mi_pct nat_mi_pct nat_noncitizen_pct {
	gen tmp_`v' = `v' if e(sample)
	egen tmpmed_`v' = median(`v')
}
replace I_L_educ = (educ_lt12_pct >= tmpmed_educ_lt12_pct) if educ_lt12_pct~=.
replace I_H_educ = (educ_colldeg_pct >= tmpmed_educ_colldeg_pct) if educ_colldeg_pct~=.
replace I_H_nonmi_mob = (res_nonmi_pct >= tmpmed_res_nonmi_pct) if res_nonmi_pct~=.
replace I_H_mi_mob = (res_mi_pct >= tmpmed_res_mi_pct) if res_mi_pct~=.
replace I_H_mi_native = (nat_mi_pct >= tmpmed_nat_mi_pct) if nat_mi_pct~=.
replace I_H_for = (nat_noncitizen_pct >= tmpmed_nat_noncitizen_pct) if nat_noncitizen_pct~=.
drop tmp*

local outpath "`path'/TEX_Tables/HoodYearFE`subf'"
capture mkdir "`outpath'"

*CONSIDER PAIRS OF DEMOGRAPHIC CHARACTERISTICS SIMULTANEOUSLY
local pair4_I = "I_H_for I_H_educ"
local pair4_x1 = "log_`indep'_x_H_for log_`indep'_x_H_educ"
local pair4_x2 = "log_prox_tax_x_H_for log_prox_tax_x_H_educ"
local pair4_iv1 = "iv_x_H_for iv_x_H_educ"
local pair4_iv2 = "iv2_x_H_for iv2_x_H_educ"

forvalues n = 4/4 {
	disp upper("`pair`n'_I'")
	
	reg log_saleamt log_`indep' `pair`n'_I' `pair`n'_x1' `log_house_X' `area_X' `school_X' `year_X' `class_X' `month_X' if yearsheld~=., `se'
	estimates store ols1
	reg log_saleamt log_`indep' log_prox_tax_n `pair`n'_I' `pair`n'_x1' `pair`n'_x2' `log_house_X' `area_X' `school_X' `year_X' `month_X' if yearsheld~=. & E_sev_ai~=., `se'
	estimates store ols2
	
	`ivcmd' log_saleamt `pair`n'_I' `log_house_X' `area_X' `school_X' `year_X' `class_X' `month_X' (log_`indep' `pair`n'_x1' = yearsheld `pair`n'_iv1'), `ivopt'
	estimates store iv1
	`ivcmd' log_saleamt `pair`n'_I' `log_house_X' `area_X' `school_X' `year_X' `class_X' `month_X' (log_`indep' `pair`n'_x1' log_prox_tax_n = yearsheld `pair`n'_iv1' log_E_sev_ai), `ivopt'
	estimates store iv2
	`ivcmd' log_saleamt `pair`n'_I' `log_house_X' `area_X' `school_X' `year_X' `class_X' `month_X' (log_`indep' `pair`n'_x1' log_prox_tax_n `pair`n'_x2' = yearsheld `pair`n'_iv1' log_E_sev_ai `pair`n'_iv2'), `ivopt'
	estimates store iv3

	outreg2 log_`indep'* log_prox* `pair`n'_I' `log_house_X' [ols1 ols2 iv1 iv2 iv3] using "`outpath'/log_`indep'_x_pair`n'_I", tex dec(3) replace adjr2 addstat(Kleibergen-Paap rk Wald F statistic, e(widstat))
	estimates drop ols1 ols2 iv1 iv2 iv3
}

log close
!copy tax_cap_est_results_ivreg2.txt "`outpath'/tax_cap_est_results_ivreg2.txt"

/**/
